<template>
  <div
    class="aui-wrapper aui-page__login"
    :style="{ '--bgurl': 'url(' + bgUrl + ')' }"
  >
    <!-- <img :src="bgUrl"/> -->
    <div class="aui-content__wrapper">
      <main class="aui-content">
        <!-- <div class="login-header">
          <h2 class="login-brand">{{ $t('brand.lg') }}</h2>
        </div> -->
        <div class="login-body">
          <div class="login-header">
            <h2 class="login-brand">{{ name }}</h2>
            <!-- <h2 class="login-brand">  {{ $t('brand.lg') }}</h2> -->
          </div>
          <h3 class="login-title">{{ $t("login.title") }}</h3>
          <el-form
            :model="dataForm"
            :rules="dataRule"
            ref="dataForm"
            @keyup.enter.native="dataFormSubmitHandle()"
            status-icon
          >
            <el-form-item prop="username">
              <p class="loginTxt">账号</p>
              <el-input
                v-model="dataForm.username"
                :placeholder="$t('login.username')"
              >
                <span slot="prefix" class="el-input__icon">
                  <svg class="icon-svg" aria-hidden="true">
                    <use xlink:href="#icon-user"></use>
                  </svg>
                </span>
              </el-input>
            </el-form-item>
            <el-form-item prop="password">
              <p class="loginTxt">密码</p>
              <el-input
                v-model="dataForm.password"
                type="password"
                :placeholder="$t('login.password')"
              >
                <span slot="prefix" class="el-input__icon">
                  <svg class="icon-svg" aria-hidden="true">
                    <use xlink:href="#icon-lock"></use>
                  </svg>
                </span>
              </el-input>
            </el-form-item>
           <!-- <el-form-item prop="captcha">
              <el-row :gutter="20">
                <el-col :span="14">
                  <el-input
                    v-model="dataForm.captcha"
                    :placeholder="$t('login.captcha')"
                  >
                    <span slot="prefix" class="el-input__icon">
                      <svg class="icon-svg" aria-hidden="true">
                        <use xlink:href="#icon-safetycertificate"></use>
                      </svg>
                    </span>
                  </el-input>
                </el-col>
                <el-col :span="10" class="login-captcha">
                  <img :src="captchaPath" @click="getCaptcha()" />
                </el-col>
              </el-row>
            </el-form-item> -->
            <el-form-item>
              <el-button
                type="primary"
                @click="dataFormSubmitHandle()"
                class="w-percent-100"
                >{{ $t("login.title") }}</el-button
              >
            </el-form-item>
          </el-form>
        </div>
      </main>
    </div>
  </div>
</template>

<script>
import Cookies from "js-cookie";
import debounce from "lodash/debounce";
import { getUUID } from "@/utils";
export default {
  data() {
    return {
      // captchaPath: "",
      name: "",
      bgUrl: require("../../../public/img/background.png"),
      dataForm: {
        username: "",
        password: "",
        uuid: "",
        // captcha: "",
      },
    };
  },
  computed: {
    dataRule() {
      return {
        username: [
          {
            required: true,
            message: this.$t("validate.required"),
            trigger: "blur",
          },
        ],
        password: [
          {
            required: true,
            message: this.$t("validate.required"),
            trigger: "blur",
          },
        ],
        // captcha: [
        //   {
        //     required: true,
        //     message: this.$t("validate.required"),
        //     trigger: "blur",
        //   },
        // ],
      };
    },
  },
  created() {
    this.getCaptcha();
    this.getSystemData();
  },
  methods: {
    // 获取验证码
    getCaptcha() {
      this.dataForm.uuid = getUUID();
      // this.captchaPath = `${window.SITE_CONFIG["apiURL"]}/captcha?uuid=${this.dataForm.uuid}`;
    },
    getSystemData() {
      this.$http.get(`/psc/systemshow/getSimpleInfo`).then((res) => {
        if (res.data.code == 0) {
          // this.$store.commit("userInfo/set_UserInfo",{
          // 	systemname:res.data.data.name,
          // 	background:res.data.data.background,
          // 	lineId:res.data.data.lineId,
          // 	stationId:res.data.data.stationId,
          // 	pslNum:res.data.data.pslNum,
          // } );
          document.title = res.data.data.name
            ? res.data.data.name
            : messages[val].brand.lg;
          Cookies.set("systemname", res.data.data.name);
          Cookies.set("background", res.data.data.backGround);
          Cookies.set(
            "lineStationName",
            res.data.data.lineName + res.data.data.stationName
          );
          Cookies.set("pslNum", res.data.data.pslNum);
          if (res.data.data.backGround) {
            this.bgUrl = res.data.data.backGround;
          }
          if (res.data.data.name) {
            this.name = res.data.data.name;
          }
        }
      });
    },
    // 表单提交
    dataFormSubmitHandle: debounce(
      function () {
        this.$refs["dataForm"].validate((valid) => {
          if (!valid) {
            return false;
          }
          this.$http
            .post("/login", this.dataForm)
            .then(({ data: res }) => {
              if (res.code !== 0) {
                // this.getCaptcha();
                return this.$message.error(res.msg);
              }
              Cookies.set("token", res.data.token);
              this.$router.replace({ name: "home-index" });
            })
            .catch(() => {});
        });
      },
      1000,
      { leading: true, trailing: false }
    ),
  },
};
</script>
<style scoped>
.aui-page__login .login-body {
  background: rgba(88, 130, 193, 0.28);
  border: 2px solid rgba(88, 130, 193, 0.8);
  border-radius: 40px;
  backdrop-filter: blur(18.38px);
  padding: 68px 93px;
}
.aui-page__login .login-body .login-title {
  color: #fff;
  font-size: 48px;
  margin: 16px 0;
  text-align: left;
}
.aui-page__login::before {
  background-image: var(--bgurl);
}
.aui-page__login .login-header {
  padding: 0;
}
.aui-page__login .login-header .login-brand {
  font-size: 24px;
  text-align: left;
}
.loginTxt {
  font-size: 18px;
  font-weight: 400;
  letter-spacing: 0px;
  line-height: 25px;
  color: rgba(255, 255, 255, 1);
  text-align: left;
  margin: 0;
}
.el-button--primary:focus,
.el-button--primary:hover {
  background: rgba(0, 52, 101, 1);
}
.el-button--primary {
  background: rgba(0, 52, 101, 1) !important;
  border-color: rgba(0, 52, 101, 1) !important;
  font-size: 20px;
}
.aui-page__login .aui-content {
  padding: 0 !important;
}
.aui-page__login .login-body,
.aui-page__login .login-footer {
  width: 622px;
}
</style>
